define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    function GetQueryString(name)
    {
        var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");
        var r = window.location.search.substr(1).match(reg);
        if(r!=null)return  unescape(r[2]); return null;
    }
    var Controller = {
        index: function () {
            var travel_id = GetQueryString('travel_id?');
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'travelmember/index?travel_id='+travel_id,
                    add_url: 'travelmember/add',
                    edit_url: 'travelmember/edit',
                    del_url: 'travelmember/del',
                    multi_url: 'travelmember/multi',
                    table: 'travel_member',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                       /* {field: 'travel_id', title: __('Travel_id')},*/
                        {field: 'username', title: '名称'},
                        {field: 'paid', title: __('Paid')},
                        {field: 'paid_fee', title: __('Paid_fee')},
                        {field: 'is_checkin', title: __('Is_checkin')},
                        {field: 'check_time', title: __('Check_time'), formatter: Table.api.formatter.datetime},
                        {field: 'deposit', title: __('Deposit')},
                        {field: 'parentname', title: '分享人'},
                        {field: 'createtime', title: '报名时间', formatter: Table.api.formatter.datetime},
                       /* {field: 'updatetime', title: __('Updatetime'), formatter: Table.api.formatter.datetime},*/
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});